package com.rt.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rt.common.annotation.Log;
import com.rt.common.core.controller.BaseController;
import com.rt.common.core.domain.AjaxResult;
import com.rt.common.enums.BusinessType;
import com.rt.system.domain.RtQuestionType;
import com.rt.system.service.IRtQuestionTypeService;
import com.rt.common.utils.poi.ExcelUtil;
import com.rt.common.core.page.TableDataInfo;

/**
 * 题型Controller
 * 
 * @author Yg
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/system/type")
public class RtQuestionTypeController extends BaseController
{
    @Autowired
    private IRtQuestionTypeService rtQuestionTypeService;

    /**
     * 查询题型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(RtQuestionType rtQuestionType)
    {
        startPage();
        List<RtQuestionType> list = rtQuestionTypeService.selectRtQuestionTypeList(rtQuestionType);
        return getDataTable(list);
    }

    @GetMapping("/availableList")
    public TableDataInfo availableList(RtQuestionType rtQuestionType)
    {
        rtQuestionType.setStatus(1);
        List<RtQuestionType> list = rtQuestionTypeService.selectRtQuestionTypeList(rtQuestionType);
        return getDataTable(list);
    }

    /**
     * 导出题型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "题型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RtQuestionType rtQuestionType)
    {
        List<RtQuestionType> list = rtQuestionTypeService.selectRtQuestionTypeList(rtQuestionType);
        ExcelUtil<RtQuestionType> util = new ExcelUtil<RtQuestionType>(RtQuestionType.class);
        return util.exportExcel(list, "题型数据");
    }

    /**
     * 获取题型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rtQuestionTypeService.selectRtQuestionTypeById(id));
    }

    /**
     * 新增题型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "题型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RtQuestionType rtQuestionType)
    {
        return toAjax(rtQuestionTypeService.insertRtQuestionType(rtQuestionType));
    }

    /**
     * 修改题型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "题型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RtQuestionType rtQuestionType)
    {
        return toAjax(rtQuestionTypeService.updateRtQuestionType(rtQuestionType));
    }

    /**
     * 删除题型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "题型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rtQuestionTypeService.deleteRtQuestionTypeByIds(ids));
    }
}
